// Toast全局插件 - 简化全局引用
import { ToastService } from './toastService.js';

// 导出ToastService的所有方法
export * from './toastService.js';

// 默认配置
const defaultOptions = {
  position: 'bottom-right'
};

// 导出默认对象，方便全局引入
export default {
  // 用于在Astro应用中初始化
  init: (options = {}) => {
    if (typeof window !== 'undefined') {
      const mergedOptions = { ...defaultOptions, ...options };
      ToastService.init(mergedOptions);
    }
  },
  // 暴露所有方法，使用与toastService一致的默认持续时间3000ms
  success: (message, duration = 3000) => ToastService.addToast({ message, type: 'success', duration }),
  error: (message, duration = 3000) => ToastService.addToast({ message, type: 'error', duration }),
  warning: (message, duration = 3000) => ToastService.addToast({ message, type: 'warning', duration }),
  info: (message, duration = 3000) => ToastService.addToast({ message, type: 'info', duration }),
  clear: () => ToastService.clearToasts()
};

// 在浏览器环境中自动初始化
if (typeof window !== 'undefined') {
  // 延迟初始化，确保DOM已加载
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', () => {
      ToastService.init(defaultOptions);
    });
  } else {
    ToastService.init(defaultOptions);
  }
}